package com.yf.dao;

import com.yf.bean.UserBean;
import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.stereotype.Repository;

@Repository
public class UserDao extends BaseDao{
    public int addUser(UserBean user) {
        int ret = this.sessionTemplate.insert(getStatement("addUser"), user);
        if (ret == 0) {
            return -1;
        }
        return user.getId();
    }

    public UserBean getById(Integer id) {
        return this.sessionTemplate.selectOne(getStatement("getById"), id);
    }

    public UserBean getByEmail(UserBean user) {
        return this.sessionTemplate.selectOne(getStatement("getByEmail"), user);
    }

    public int updateUserLoginTime(UserBean user) {
        return this.sessionTemplate.update(getStatement("updateLoginTime"), user);
    }

    public int activateUser(Integer id) {
        return this.sessionTemplate.update(getStatement("activateUser"), id);
    }

    public boolean existUsername(Integer nameID) {
        Integer n = this.sessionTemplate.selectOne(getStatement("existUsername"), nameID);
        return n > 0;
    }

    public boolean existEmail(Integer emailID) {
        Integer n = this.sessionTemplate.selectOne(getStatement("existEmail"), emailID);
        return n > 0;
    }

    public int markBlackUser(Long uid) {
        return this.sessionTemplate.update(getStatement("markBlackUser"), uid);
    }

    public Integer getUserPriority(Integer uid) {
        return sessionTemplate.selectOne(getStatement("getUserPriority"), uid);
    }

    public int resetUserPass(UserBean userBean) {
        return sessionTemplate.update(getStatement("resetUserPass"), userBean);
    }

    public int resetUsername(UserBean userBean) {
        return sessionTemplate.update(getStatement("resetUsername"), userBean);
    }
}
